import unittest
import os
import time
from HTMLTestRunner_cn import HTMLTestRunner

# 定义需要执行的多个文件夹路径
test_folders = [
    # os.path.join(os.path.dirname(__file__), 'wjx'),
     # os.path.join(os.path.dirname(__file__), 'lxf'),
     os.path.join(os.path.dirname(__file__), 'finance_task_log_knowledge_letter')
]

# 初始化测试套件并循环添加所有用例
combined_suite = unittest.TestSuite()
for folder in test_folders:
    combined_suite.addTests(
        unittest.defaultTestLoader.discover(folder, pattern="test_*.py")
    )

# 执行测试并生成报告
report_path = os.path.join(os.path.dirname(__file__), 'report')
os.makedirs(report_path, exist_ok=True)  # 确保报告目录存在
filename = os.path.join(report_path, f"测试报告_{time.strftime('%Y%m%d%H%M%S')}.html")

with open(filename, "wb") as f:
    runner = HTMLTestRunner(stream=f, title="多文件夹合并测试报告")
    runner.run(combined_suite)
